package com.semanticweb.webapp.model.rbac;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Version;
import javax.validation.constraints.NotNull;

import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

@Entity
@Table(name = "operations")
public class Operation extends AbstractPersistedEntity {
    
	private static final long serialVersionUID = -4343646516265837811L;

	@Version
    @Column(name = "version")
    private Integer version;

    @OneToMany(cascade = CascadeType.ALL, mappedBy="permissionOperation")
    private Set<Permission> permissions = new HashSet<Permission>();

    private Boolean canCreate;

    private Boolean canRead;

    private Boolean canUpdate;

    private Boolean canDelete;

    @NotNull
    private String operationName;
	
	public Set<Permission> getPermissions() {
        return this.permissions;
    }
    
    public void setPermissions(Set<Permission> permissions) {
        this.permissions = permissions;
    }
    
    public Boolean getCanCreate() {
        return this.canCreate;
    }
    
    public void setCanCreate(Boolean canCreate) {
        this.canCreate = canCreate;
    }
    
    public Boolean getCanRead() {
        return this.canRead;
    }
    
    public void setCanRead(Boolean canRead) {
        this.canRead = canRead;
    }
    
    public Boolean getCanUpdate() {
        return this.canUpdate;
    }
    
    public void setCanUpdate(Boolean canUpdate) {
        this.canUpdate = canUpdate;
    }
    
    public Boolean getCanDelete() {
        return this.canDelete;
    }
    
    public void setCanDelete(Boolean canDelete) {
        this.canDelete = canDelete;
    }
    
    public String getOperationName() {
        return this.operationName;
    }
    
    public void setOperationName(String operationName) {
        this.operationName = operationName;
    }
    
    public Integer getVersion() {
        return this.version;
    }
    
    public void setVersion(Integer version) {
        this.version = version;
    }
	
	public String toString() {
        return ReflectionToStringBuilder.toString(this, ToStringStyle.SHORT_PREFIX_STYLE);
    }
}
